package com.hundred.item.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.hundred.item.dao.ItemCompareDAO;
import com.hundred.item.dao.dataobject.ItemCompareDO;

public class ItemCompareDAOImpl extends SqlMapClientDaoSupport implements ItemCompareDAO {

	public int insertCompareModel(ItemCompareDO itemCompareDO) {
		
		this.getSqlMapClientTemplate().insert("ItemCompareDAO.insertItemCompareRes", itemCompareDO);
		return 1;
	}

	public int updateCompareModel(ItemCompareDO itemCompareDO) {
		
		return this.getSqlMapClientTemplate().update("ItemCompareDAO.updateItemCompareModel", itemCompareDO);
		
	}

	public ItemCompareDO getCompareModelById(long id) {
		
		return (ItemCompareDO) this.getSqlMapClientTemplate().queryForObject("ItemCompareDAO.getItemCompareModelById",id);

	}

	public List<ItemCompareDO> getCompareModelByUserId(long userId) {
		
		List<ItemCompareDO> result = new ArrayList<ItemCompareDO>();
		
		@SuppressWarnings("unchecked")
		List<ItemCompareDO> queryResult = this.getSqlMapClientTemplate().queryForList("ItemCompareDAO.selectUserCompareRes",userId);

		if(queryResult!=null && queryResult.size()>0){
			result = queryResult;
		}
		return result;
		
	}

	public List<ItemCompareDO> getCompareModelByWinnerItemId(long winnerItemId) {

		List<ItemCompareDO> result = new ArrayList<ItemCompareDO>();
		
		@SuppressWarnings("unchecked")
		List<ItemCompareDO> queryResult = this.getSqlMapClientTemplate().queryForList("ItemCompareDAO.getItemCompareModelByWinnerItemId",winnerItemId);

		if(queryResult!=null && queryResult.size()>0){
			result = queryResult;
		}
		return result;
	}

	public List<ItemCompareDO> getCompareModelByWinnerItemIdAndStatus(
			long winnerItemId, int status) {
		
		Map<String, Long> parameterMap = new HashMap<String , Long>();
		
		parameterMap.put("winnerItemId", winnerItemId);
		
		parameterMap.put("status", (long) status);
		
		List<ItemCompareDO> result = new ArrayList<ItemCompareDO>();
		
		@SuppressWarnings("unchecked")
		List<ItemCompareDO> queryResult = this.getSqlMapClientTemplate().queryForList("ItemCompareDAO.getItemCompareModelByWinnerItemIdAndStatus",parameterMap);

		if(queryResult!=null && queryResult.size()>0){
			result = queryResult;
		}
		return result;
	}

	public int deleteCompareModelById(long id) {
		
		return this.getSqlMapClientTemplate().update("ItemCompareDAO.deleteItemCompareModelById", id);
	}

	public int deleteCompareModelByUserId(long userId) {
		// TODO Auto-generated method stub
		return 0;
	}

}
